<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title><?=$this->page_title?></title>
    <link rel="stylesheet" type="text/css" href="/style/css/base.css"/>
    <link rel="stylesheet" type="text/css" href="/style/css/swiper.min.css"/>
    <link rel="stylesheet" type="text/css" href="/style/css/xshop.css?ver=20170916" />
    <script src="/style/js/jquery-1.12.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/style/js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/style/js/xShop.js" type="text/javascript" charset="utf-8"></script>
    </head>
<body>
<div class="outwrap">
	<!--top-->	
	<!-- <div class="topbar clearfix topvh">
		<a href="/mystore/account_manage" class="btn-back">
			<i class="ico-back"></i><span>修改地区</span>
		</a>
	</div> -->
  <div class="meinner-adr-add">
    <div class="iptform iptformm30">
    <form action="" method="post" id="dataForm">
       <div class="item-ipt item-slt">
          <span class="name">所属省份</span><input type="text" class="slt" placeholder="<?php if($this->data['info']['province_id']>0) echo $this->data['region'][$this->data['info']['province_id']]; else echo '请选择';?>" />
          <select id="_province_id" name="province_id">
          <option value="">省份</option>
                <?php foreach($this->province as $region_id => $region_name){?>
                <option value="<?=$region_id?>" <?php if($region_id==$this->data['info']['province_id']):?>selected="selected"<?php endif;?>><?=$region_name?></option>
               <?php  }?>
              </select>
        </div>
        <div class="item-ipt item-slt">
          <span class="name">所属市/区</span><input type="text" class="slt" placeholder="<?php if($this->data['info']['city_id']>0) echo $this->data['region'][$this->data['info']['city_id']]; else echo '请选择';?>" />
        <select id="_city_id" name="city_id">
              <option value="">市/区</option>
              <?php
                foreach($this->data['city_list'] as $region_id => $region_name){?>
                 <option value="<?=$region_id?>" <?php if($region_id==$this->data['info']['city_id']):?>selected="selected"<?php endif;?>><?=$region_name?></option>
               <?php  }?>
            </select>
            </div>
        <div class="item-ipt item-slt">
          <span class="name">所属县/区</span><input type="text" class="slt" placeholder="<?php if($this->data['info']['county_id']>0) echo $this->data['region'][$this->data['info']['county_id']]; else echo '请选择';?>"  />
            <select id="_county_id" name="county_id">
              <option value="">县/区</option> 
              <?php
                foreach($this->data['county_list'] as $region_id => $region_name){?>
                <option value="<?=$region_id?>" <?php if($region_id==$this->data['info']['county_id']):?>selected="selected"<?php endif;?>><?=$region_name?></option>
                 <?php  }?>            
            </select>
            </div>

     <input type="hidden" name="act" value='save_info'>

    </form>
    </div>
    <div class="btnwrap">
      <input type="button" class="btn-mexl btn-bc" value="保存" id="save_btn" />
    </div>
  </div>


</div>
<script type="text/javascript" src="/style/js/sweet-alert.min.js"></script>
<link type="text/css" rel="stylesheet" href="/style/css/sweet-alert.css">
<script type="text/javascript">

$(document).ready(function(e) {

  $("#_province_id").bind("change",function(){

    _get_region( $(this).val() ,"_city_id");
  });

  $("#_city_id").bind("change",function(){

    _get_region( $(this).val() ,"_county_id");
  });


  $('.item-slt select').change(function(){
      var thisTxt = $(this).find('option:selected').text();
      $(this).prev('.slt').val(thisTxt);
    });
   $('.psfs span').on('click',function(){ console.log("sapn");
        $(this).addClass('on').siblings().removeClass('on');
        $("#sex").val($(this).attr("data-value"));
    });


 $("#save_btn").click(function(){
  if($("#_province_id").val()==""){
    swal("请选择省份");
    return false;
  }
  if($("#_city_id").val()==""){
    swal("请选择市/区");
    return false;
  }

  $(this).hide();
   $.ajax({type:'POST',url:"ajax",dataType:'json',data:$('#dataForm').serialize(), success: function(data) {
               $("#save_btn").show();
                if(data.code==200){
                    swal("保存成功",false,"success");
					setTimeout("history.back()",2100);
                }else{
                     swal("保存失败",false,"error");
                     
                }
               
            }

            });
 });


});

function _get_region(region_id,obj_id)
{
  if(obj_id=="_city_id"){
    $("#_city_id,#_county_id").empty();
    $("#_city_id").prev('.slt').val("请选择");
    $("#_county_id").prev('.slt').val("请选择");
    $("#_city_id").append('<option value="">市/区</option>');
    $("#_county_id").append('<option value="">县/区</option>');
  }
  else if(obj_id=="_county_id"){
    $("#_county_id").prev('.slt').val("请选择");
    $("#_county_id").empty();   
    $("#_county_id").append('<option value="">县/区</option>');
  }

  if(region_id!=""){
    $.post("ajax",{
      "act":"region",
      "parent_id":parseInt(region_id),
      "mr":Math.random()
    },function(msg){
      if(msg!=""){
        var json = eval("("+msg+")");
        if(json.code==200){
          $.each(json.data,function(region_id,region_name){

            $("#"+obj_id).append('<option value="'+region_id+'">'+region_name+'</option>');

          });
        }       
      }
    });
  }
}
</script>

<!--底部导航-->
	<div class="foot-menu">
		<ul class="clearfix">
			<li><a href="/index/index"><i class="ico-1"></i><span>首页</span></a></li>
        
        <li><a href="/cart/cart"><i class="ico-5"></i><span>购物车</span></a></li>
        <li><a href="#"><i class="ico-3"></i><span>客服</span></a></li>
        <li class="on"><a href="/user/index"><i class="ico-4"></i><span>我的</span></a></li>
		</ul>
	</div>
</body>
</html>
